<template>
  <div class="app-container">
    <el-card class="box-card">
      <div slot="header" style="display: flex;justify-content: space-between;width: 100%;
      font-size: 16px;align-items: center;">
        <span>车辆详情</span>
        <el-button @click="pageReturn">返回</el-button>
      </div>
      <div class="top-card">
        <!--        <el-image src="" style="width: 100px; height: 100px"></el-image>-->
        <div class="top-card-right">
          <div style="font-size: 16px;display: flex;justify-content: space-between;">
            <div>
              <span style="font-weight: 600">车架号：</span><span>{{ detailForm.vinNo }}</span>
            </div>
            <div>
              <span style="font-weight: 600">车辆状态：</span><span>
                {{ selectDictLabel(dict.type.car_business_type, detailForm.businessType) }}</span>
            </div>
          </div>
          <div>
            <span>品牌/车型/车款：</span><span>{{
              `${detailForm.brandName}/${detailForm.seriesName}/${detailForm.modelName}`
            }}</span>
          </div>
          <div>
            <span>车辆归属：</span><span>{{ detailForm.ascription }}</span>
          </div>
        </div>
      </div>
    </el-card>

    <el-tabs v-model="activeName" @tab-click="handleClick">
      <el-tab-pane label="保养详情" name="byxq">
        <el-form :model="detailForm" v-if="isForm" class="el-form">
          <el-card class="box-card">
            <div slot="header" class="header-card">
              <span class="header-card-title">车辆信息</span>
            </div>
            <el-row :gutter="20">
              <el-col :span="8">
                <el-form-item label="车架号:">
                  <span>{{ detailForm.vinNo }}</span>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="车牌号:">
                  <span>{{ detailForm.carNo }}</span>
                </el-form-item>
              </el-col>

              <el-col :span="8">
                <el-form-item label="品牌/车型/车款:">
                  <span>{{
                      `${detailForm.brandName ? detailForm.brandName : ''}${detailForm.seriesName ? detailForm.seriesName + '/' : ''}${detailForm.modelName ? detailForm.modelName + '/' : ''}`
                    }}</span>
                </el-form-item>
              </el-col>
            </el-row>

            <el-row :gutter="20">
              <el-col :span="8">
                <el-form-item label="客户名称:">
                  <span>{{ detailForm.customerName }}</span>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="租赁合同日期:">
                  <span>{{ detailForm.leaseStartTime }} ~
                    {{ detailForm.leaseEndTime }}</span>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="租赁台数:">
                  <span>{{ detailForm.leaseNum }}</span>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="8">
                <el-form-item label="车辆行驶里程:">
                  <span>{{ detailForm.travelMeligile }}</span>
                </el-form-item>
              </el-col>

              <el-col :span="8">
                <el-form-item label="注册日期:">
                  <span>{{ detailForm.registerTime }}</span>
                </el-form-item>
              </el-col>

              <el-col :span="8">
                <el-form-item label="预算费用:">
                  <span>{{ detailForm.budgetPrice }}</span>
                </el-form-item>
              </el-col>
            </el-row>
            <!--            <el-row :gutter="20">-->
            <!--              <el-col :span="8">-->
            <!--                <el-form-item label="已保养成本:">-->
            <!--                  <span>{{ detailForm.repairedPrice }}</span>-->
            <!--                </el-form-item>-->
            <!--              </el-col>-->

            <!--              <el-col :span="8">-->
            <!--                <el-form-item label="剩余预估费用:">-->
            <!--                  <span>{{ detailForm.carSurplusPrice }}</span>-->
            <!--                </el-form-item>-->
            <!--              </el-col>-->
            <!--              <el-col :span="8">-->
            <!--                <el-form-item label="保养类型:">-->
            <!--                  <span>-->
            <!--                    {{-->
            <!--                      selectDictLabel(-->
            <!--                          dict.type.maintain_type,-->
            <!--                          detailForm.maintainType-->
            <!--                      )-->
            <!--                    }}</span>-->
            <!--                </el-form-item>-->
            <!--              </el-col>-->
            <!--            </el-row>-->
          </el-card>
          <el-card class="box-card">
            <div slot="header" class="header-card">
              <span class="header-card-title">保养信息</span>
            </div>
            <el-row :gutter="20">
              <el-col :span="8">
                <el-form-item label="预计保养开始时间:" prop="expectStartTime">
                  <span>{{ detailForm.expectStartTime }}</span>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="预计保养结束时间:" prop="expectEndTime">
                  <span>{{ detailForm.expectEndTime }}</span>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="签约保养厂/保养厂:" prop="maintainShop">
                  <span>{{ detailForm.maintainShop }}</span>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="8">
                <el-form-item label="故障描述:" prop="faultDescribe">
                  <span>{{ detailForm.faultDescribe }}</span>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="保养厂报价:" prop="maintainQuoter">
                  <span>{{ format_thousand(detailForm.maintainQuoter) }}</span>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="是否符合索赔理由:" prop="reasonForClaim">
                  <span>{{
                      detailForm.reasonForClaim == "1"
                          ? "是"
                          : detailForm.reasonForClaim == "2"
                              ? "否"
                              : ""
                    }}</span>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="8">
                <el-form-item label="不符合索赔理由:" prop="claimantReason">
                  <span>{{ detailForm.claimantReason }}</span>
                </el-form-item>
              </el-col>

              <el-col :span="8">
                <el-form-item label="是否有同车型（处置车辆）对换配件:" prop="swappingAccessories">
                  <span>{{
                      detailForm.swappingAccessories == "1"
                          ? "是"
                          : detailForm.swappingAccessories == "2"
                              ? "否"
                              : ""
                    }}</span>
                </el-form-item>
              </el-col>
            </el-row>

            <el-row>
              <el-col>
                <el-form-item label="综合建议方案:" prop="comprehensiveRecommendations">
                  <span>{{ detailForm.comprehensiveRecommendations }}</span>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col>
                <el-form-item label="备注:" prop="maintainRemark">
                  <span>{{ detailForm.maintainRemark }}</span>
                </el-form-item>
              </el-col>
            </el-row>
          </el-card>
          <el-card class="box-card">
            <div slot="header" class="header-card">
              <span class="header-card-title">保养项目明细</span>
            </div>
            <div style="margin-bottom: 14px">保养合计费用：</div>
            <el-row style="margin-bottom: 14px">
              <el-col>
                <el-table size="mini" :data="detailForm.carMaintainProjectList" border style="width: 100%">
                  <el-table-column label="序号" type="index"/>
                  <el-table-column label="保养项目名称" align="center" prop="maintainName">
                  </el-table-column>
                  <el-table-column label="金额/元" min-width="100" align="center" prop="price">
                    <template #default="{row}">
                      <span>{{ format_thousand(row.price) }}</span>
                    </template>
                  </el-table-column>
                  <el-table-column label="详细信息" align="center" prop="detailedInfo">
                  </el-table-column>
                </el-table>
              </el-col>
            </el-row>
            <el-row>
              <el-col>
                <el-form-item label="查看附件:">
                  <ImageCommon v-model="detailForm.maintainProjectUrl" :disabled="true"/>
                </el-form-item>
              </el-col>
            </el-row>
          </el-card>
          <el-card class="box-card">
            <div slot="header" class="header-card">
              <span class="header-card-title">保养反馈</span>
            </div>

            <el-row :gutter="20">
              <el-col :span="8">
                <el-form-item label="实际保养开始时间:" prop="actualStartTime">
                  <span>{{ detailForm.actualStartTime }}</span>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="实际保养结束时间:" prop="actualStartTime">
                  <span>{{ detailForm.actualEndTime }}</span>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="是否个人垫付:">
                  <span>{{
                      detailForm.feedbackAdvancePayment == "1"
                          ? "是"
                          : detailForm.feedbackAdvancePayment == "2"
                              ? "否"
                              : ""
                    }}</span>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="8">
                <el-form-item label="付款类型:">
                  <span>
                    {{
                      selectDictLabel(dict.type.pay_type, detailForm.payType)
                    }}</span>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item label="保养完成照片:">
                  <ImageCommon v-model="detailForm.maintainCompleteUrl" :disabled="true"/>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="保养凭证:">
                  <ImageCommon v-model="detailForm.balanceUrl" :disabled="true"/>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="8">
                <el-form-item label="保养意见反馈:">
                  <span>{{ detailForm.driverName }}</span>
                </el-form-item>
              </el-col>
            </el-row>
          </el-card>
        </el-form>
      </el-tab-pane>

      <el-tab-pane label="保养记录" name="byjl">
        <el-card class="box-card">
          <el-row :gutter="20">
            <el-form>
              <el-col :span="8">
                <el-form-item label="车辆保养总次数:">
                  <span> {{ form.totalCount }}</span>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="车辆保养总预算:">
                  <span>{{ format_thousand(form.carTaxTotalMoney) }}</span>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="车辆剩余预估费用:">
                  <span>{{ format_thousand(form.carTaxTotalMoney) }}</span>
                </el-form-item>
              </el-col>
            </el-form>
          </el-row>
          <el-row>
            <el-table :data="tableData" border style="width: 100%">
              <el-table-column label="操作" fixed align="center" width="100">
                <template #default="{row}">
                  <el-button type="text" @click="handleRoute(row)">查看</el-button>
                </template>
              </el-table-column>
              <el-table-column prop="maintainType" align="center" label="保养类型">
                <template #default="{row}">
                  <span v-if="row.maintainType == 1">首保</span>
                  <span v-if="row.maintainType == 2">非首保</span>
                </template>
              </el-table-column>
              <el-table-column prop="customerName" show-overflow-tooltip align="center" label="客户名称">
              </el-table-column>
              <el-table-column prop="expectStartTime" align="center" label="预计开始时间">
              </el-table-column>
              <el-table-column prop="expectEndTime" align="center" label="预计结束时间">
              </el-table-column>
              <el-table-column prop="actualStartTime" align="center" label="实际际开始时间">
              </el-table-column>
              <el-table-column prop="actualEndTime" align="center" label="实际结束时间">
              </el-table-column>
              <el-table-column prop="ascription" show-overflow-tooltip align="center" label="车辆归属">
              </el-table-column>
              <el-table-column prop="ascription" show-overflow-tooltip align="center" label="所在城市">
              </el-table-column>
              <el-table-column prop="totalMoney" align="center" label="保养费用">
              </el-table-column>
            </el-table>
          </el-row>
        </el-card>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script>
import {getToken} from "@/utils/auth";
import {
  delMaintain,
  getDetails,
  queryPageRecord,
} from "@/api/zcwh/byglApi.js";

import imgList from "../imgList.vue";
import {getMaintenanceMessage} from "@/api/zcwh/vehicleTabs.js";

export default {
  name: "nounDetails",
  dicts: ["car_business_type", "contract_type", "maintain_type", "pay_type"],
  components: {imgList},
  data() {
    return {
      loading: false,
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        carId: "2",
        maintenanceType: "2",
      },

      total: 0,
      isForm: false,
      routeQuery: {},
      activeName: "byxq",
      detailForm: {
        maintainCompleteUrl: "1749676873802362881,1749676886876008450",
        maintainProjectUrl: "1749676886876008450,1749676908145324034",
        balanceUrl: "",
      },

      tableData: [],
      form: {}
    };
  },
  watch: {},
  computed: {
    selectDictLabel() {
      return (arr, type) => {
        let name = "";
        arr.map((v) => {
          if (type == v.value) {
            name = v.label;
          }
        });
        return name;
      };
    },
  },
  created() {
    if(this.$route.query.id){
      this.getDetails(this.$route.query.id);
    }
  },
  methods: {
    handleRoute(row) {
      this.activeName = "byxq"
      this.getDetails(row.maintainId);
    },

    pageReturn() {
      this.$tab.closePage().then(({visitedViews}) => {
        this.$router.push({
          path: "/clgl/nounList",
        });
      });

    },
    handleClick(tab, event) {
      if (this.activeName === "byjl") {
        this.handleList()
      }
    },
    getDetails(id) {
      getDetails(id).then((res) => {
        if (res.code === 200) {
          this.detailForm = res.data || {};

          this.isForm = true;
        }
      });
    },
    async handleList() {
      this.loading = true;
      try {
        const res = await getMaintenanceMessage(this.detailForm.carId)
        this.form = res
        this.tableData = res.vo;
      } finally {
        this.loading = false;
      }
    },
  },
};
</script>


<style lang="scss" scoped>
.box-card {
  font-size: 14px;
  margin-bottom: 20px;

  .box-card-inp {
    display: flex;
    align-items: center;
    margin-bottom: 20px;

    .inp-name {
      width: 140px;
      text-align: right;
      font-size: 14px;
    }

    .inp-name-r {
      flex: 1;
    }
  }

  .top-card {
    display: flex;

    img {
      display: block;
      width: 200px;
      height: 160px;
    }

    .top-card-right {
      flex: 1;
      margin-left: 20px;
      font-size: 14px;
      line-height: 36px;
    }
  }

  ::v-deep .el-card__header {
    padding: 0;
    height: 48px;
    margin: 0 14px;
    display: flex;
    align-items: center;

    .header-card {
      display: flex;
      justify-content: space-between;
      align-items: center;
      flex: 1;

      .header-card-title {
        font-size: 16px;
        font-weight: 500;
        color: #333333;
      }
    }
  }

  ::v-deep .el-card__body {
    padding: 10px 14px;
  }
}

.el-form {
  ::v-deep.el-form-item {
    display: flex;
  }

  ::v-deep .el-form-item {
    margin-bottom: 12px;
  }

  ::v-deep.el-form-item__content {
    line-height: normal;
    flex: 1;
    margin-left: 0 !important;
  }

  ::v-deep.el-form-item__label {
    line-height: normal;
    font-size: 14px;
    font-family: PingFangSC, PingFang SC;
    font-weight: 400;
    color: #646464;
  }
}
</style>
